﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace Xin478.CSWork.Client
{

    public class MyDataGridView : System.Windows.Forms.DataGridView
    {
        Color BackgroundBeginColor = Color.FromArgb(166, 208, 249);
        Color BackgroundEndColor = Color.FromArgb(160, 203, 248);
        Color TopBorderColor = Color.FromArgb(200, 226, 251);
        Color BottomBorderColor1 = Color.FromArgb(177, 211, 248);
        Color BottomBorderColor2 = Color.FromArgb(129, 175, 236);
        Color SplitBorderColor1 = Color.FromArgb(118, 177, 239);
        Color SplitBorderColor2 = Color.FromArgb(197, 222, 249);

        public MyDataGridView()
        {
            this.CellPainting += new DataGridViewCellPaintingEventHandler(MyDataGridView_CellPainting);
        }

        void MyDataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.RowIndex == -1)
            {
                Rectangle border = e.CellBounds;
 
                using (LinearGradientBrush brush = new LinearGradientBrush(e.CellBounds, BackgroundBeginColor, BackgroundEndColor, LinearGradientMode.Vertical))
                {
                    e.Graphics.FillRectangle(brush, e.CellBounds);
                    //Rectangle border = e.CellBounds;
                    //border.Width -= 1;
                    //e.Graphics.DrawRectangle(Pens.Gray, border);
                }
                using (Pen p = new Pen(TopBorderColor))
                {
                    e.Graphics.DrawLine(p, border.X, 1, border.X + border.Width-1, 1);

                    p.Color = BottomBorderColor1;
                    e.Graphics.DrawLine(p, border.X, border.Height - 2, border.X + border.Width-1, border.Height - 2);

                    p.Color = BottomBorderColor2;
                    e.Graphics.DrawLine(p, border.X, border.Height-1, border.X + border.Width-1, border.Height-1);

                    if (e.ColumnIndex != -1 && (!this.RowHeadersVisible && e.ColumnIndex!=0))
                    {
                        p.Color = SplitBorderColor1;
                        e.Graphics.DrawLine(p, border.X, 3, border.X, border.Height - 3);

                        p.Color = SplitBorderColor2;
                        e.Graphics.DrawLine(p, border.X + 1, 3, border.X + 1, border.Height - 3);
                        border.X += 2;
                        border.Width -= 2;
                    }
                }
                border.Y += 2;
                border.Height -= 4;

                e.PaintContent(e.CellBounds);
                e.Handled = true;
            }
        }

    }
}
